package com.dhnsoft.代码随想录.哈希表;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * ClassName: d04_1_两数之和
 * Package: com.dhnsoft.代码随想录.哈希表
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/14 9:37
 * @Version 1.0
 */
public class d04_1_两数之和 {

    public static void main(String[] args) {

    }

    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();
        int[] t = new int[2];
        for (int i=0;i<nums.length;i++){
            int temp = target-nums[i];
            if(map.containsKey(temp)){
                t[0] = i;
                t[1] = map.get(temp);
            }
            map.put(nums[i],i);
        }
        return t;
    }
}
